package com.bit.frige;

import java.io.InputStream;
import java.util.ArrayList;
import android.annotation.SuppressLint;
//import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

import com.bit.frige.DB.DBContactHelper;
import com.bit.frige.DB.FoodDTO;
import com.bit.frige.Tip.TipActivity;
import com.bit.frige.basket.BasketMainActivity;
import com.bit.frige.recipe.Recipefoodlist;

public class MainActivity extends Activity {

	private ImageButton btn1;
	private ImageButton btn2;
	private ImageButton btn3;
	private ImageButton btn4;
	ArrayList<FoodDTO> list;
	InputStream is;
	DBContactHelper db;
 
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// int length = getResources().getDimensionPixelSize(R.dimen.length);
		final float scale = getResources().getDisplayMetrics().density;
		@SuppressWarnings("unused")
		Button btn = (Button) findViewById(R.id.button1);

		Intent intent = getIntent();
		int load = intent.getIntExtra("load", 0);
		if (load == 0) {
			startActivity(new Intent(this, LoadingActivity.class));
		}
		load = 1;
		// 식사관리BUTTON
		btn1 = (ImageButton) findViewById(R.id.foodbtn);
		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						MainFoodActivity.class);
				startActivity(intent);
			}
		});

		// 레시피 BUTTON
		btn2 = (ImageButton) findViewById(R.id.recipebtn);
		btn2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						Recipefoodlist.class);
				startActivity(intent);
			}
		});
	//도움말 BUTTON
		btn4 = (ImageButton) findViewById(R.id.redicon);
		btn4.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						TipActivity.class);
				startActivity(intent);
			}
		});
		
		//장바구니 BUTTON
		btn4 = (ImageButton) findViewById(R.id.basketbtn);
		btn4.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						BasketMainActivity.class);
				startActivity(intent);
			}
		});
		
		
		Button guidbtn = (Button) findViewById(R.id.guidbtn);
		guidbtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						GuideSlideActivity.class);
				startActivity(intent);
			}
		});
		Button devbtn = (Button) findViewById(R.id.devbtn);
		devbtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),
						DeveloperActivity.class);
				startActivity(intent);
			}
		});

	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			new AlertDialog.Builder(this)
					.setTitle("종료")
					.setMessage("종료하시겠어요?")
					.setPositiveButton("예",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
									finish();
								}
							}).setNegativeButton("아니오", null).show();
			return false;
		default:
			return false;
		}

	}
}
